/*     */ package com.xhgk.test;
/*     */ import com.xhgk.domain.ConstantParam;
/*     */ import com.xhgk.utis.LuceneTool;
/*     */ import java.io.IOException;
/*     */ import java.text.SimpleDateFormat;
/*     */ import java.util.Date;
/*     */ import org.apache.commons.lang.StringUtils;
/*     */ import org.apache.lucene.document.Document;
/*     */ import org.apache.lucene.document.Field;
/*     */ import org.apache.lucene.document.Fieldable;
/*     */ import org.apache.lucene.document.NumericField;
/*     */ import org.apache.lucene.index.CorruptIndexException;
/*     */ import org.apache.lucene.index.IndexWriter;
/*     */ import org.apache.lucene.search.BooleanClause;
/*     */ import org.apache.lucene.search.BooleanQuery;
/*     */ import org.apache.lucene.search.IndexSearcher;
/*     */ import org.apache.lucene.search.Query;
/*     */ import org.apache.lucene.search.ScoreDoc;
/*     */ import org.apache.lucene.search.TermRangeQuery;
/*     */ import org.apache.lucene.search.TopDocs;
/*     */ 
/*     */ public class Demo1 {
/*     */   public static void main(String[] args) throws IOException {
/*  24 */     ConstantParam.indexDirectory = "D:\\resource\\zgdsyj\\index2";
/*     */     
/*  26 */     IndexSearcher searcher = LuceneTool.getSearcher();
/*  27 */     BooleanQuery bqs = new BooleanQuery();
/*     */     
/*  29 */     String stime = "20151201";
/*  30 */     String etime = "20151231";
/*  31 */     if (StringUtils.isNotEmpty(stime) && StringUtils.isNotEmpty(etime)) {
/*     */       
/*  33 */       if (StringUtils.isEmpty(stime)) {
/*     */         
/*  35 */         stime = "19700101";
/*     */       }
/*     */       else {
/*     */         
/*  39 */         stime = stime.replaceAll("-", "");
/*     */       } 
/*     */       
/*  42 */       if (StringUtils.isEmpty(etime)) {
/*     */         
/*  44 */         etime = (new SimpleDateFormat("yyyyMMdd")).format(new Date());
/*     */       }
/*     */       else {
/*     */         
/*  48 */         etime = etime.replaceAll("-", "");
/*     */       } 
/*  50 */       TermRangeQuery rangeQuery = new TermRangeQuery("date", stime, etime, true, true);
/*  51 */       bqs.add((Query)rangeQuery, BooleanClause.Occur.MUST);
/*     */     } 
/*  53 */     System.out.println(bqs);
/*  54 */     TopDocs search = searcher.search((Query)bqs, 2000);
/*  55 */     ScoreDoc[] scoreDocs = search.scoreDocs; byte b; int i; ScoreDoc[] arrayOfScoreDoc1;
/*  56 */     for (i = (arrayOfScoreDoc1 = scoreDocs).length, b = 0; b < i; ) { ScoreDoc docs = arrayOfScoreDoc1[b];
/*  57 */       Document doc = searcher.doc(docs.doc);
/*  58 */       System.out.println(String.valueOf(doc.get("name")) + "=" + doc.get("date")); b++; }
/*     */     
/*  60 */     System.out.println(search.totalHits);
/*     */   }
/*     */   
/*     */   private static void createIndex() throws CorruptIndexException, IOException {
/*  64 */     IndexWriter indexWriter = LuceneTool.getIndexWriter();
/*     */     
/*  66 */     Document doc = new Document();
/*  67 */     doc.add((Fieldable)new Field("date", "20150101", Field.Store.YES, Field.Index.NOT_ANALYZED));
/*  68 */     doc.add((Fieldable)new Field("name", "张1", Field.Store.YES, Field.Index.NOT_ANALYZED));
/*  69 */     doc.add((Fieldable)new Field("text", "爱读书", Field.Store.YES, Field.Index.ANALYZED));
/*  70 */     indexWriter.addDocument(doc);
/*     */     
/*  72 */     doc = new Document();
/*  73 */     doc.add((Fieldable)new Field("date", "20151201", Field.Store.YES, Field.Index.NOT_ANALYZED));
/*  74 */     doc.add((Fieldable)new Field("name", "张1", Field.Store.YES, Field.Index.NOT_ANALYZED));
/*  75 */     doc.add((Fieldable)new Field("text", "爱读书", Field.Store.YES, Field.Index.ANALYZED));
/*  76 */     indexWriter.addDocument(doc);
/*     */     
/*  78 */     doc = new Document();
/*  79 */     doc.add((Fieldable)new Field("date", "201711", Field.Store.YES, Field.Index.NOT_ANALYZED));
/*  80 */     doc.add((Fieldable)new Field("name", "张1", Field.Store.YES, Field.Index.NOT_ANALYZED));
/*  81 */     doc.add((Fieldable)new Field("text", "爱读书", Field.Store.YES, Field.Index.ANALYZED));
/*  82 */     indexWriter.addDocument(doc);
/*     */     
/*  84 */     doc = new Document();
/*  85 */     doc.add((Fieldable)new Field("date", "201811", Field.Store.YES, Field.Index.NOT_ANALYZED));
/*  86 */     doc.add((Fieldable)new Field("name", "张1", Field.Store.YES, Field.Index.NOT_ANALYZED));
/*  87 */     doc.add((Fieldable)new Field("text", "爱读书", Field.Store.YES, Field.Index.ANALYZED));
/*  88 */     indexWriter.addDocument(doc);
/*     */     
/*  90 */     doc = new Document();
/*  91 */     doc.add((Fieldable)new Field("date", "201511", Field.Store.YES, Field.Index.NOT_ANALYZED));
/*  92 */     doc.add((Fieldable)new Field("name", "张1", Field.Store.YES, Field.Index.NOT_ANALYZED));
/*  93 */     doc.add((Fieldable)new Field("text", "爱读书", Field.Store.YES, Field.Index.ANALYZED));
/*  94 */     indexWriter.addDocument(doc);
/*     */     
/*  96 */     doc = new Document();
/*  97 */     doc.add((Fieldable)new Field("date", "20141101", Field.Store.YES, Field.Index.NOT_ANALYZED));
/*  98 */     doc.add((Fieldable)new Field("name", "张1", Field.Store.YES, Field.Index.NOT_ANALYZED));
/*  99 */     doc.add((Fieldable)new Field("text", "爱读书", Field.Store.YES, Field.Index.ANALYZED));
/* 100 */     indexWriter.addDocument(doc);
/*     */     
/* 102 */     doc = new Document();
/* 103 */     doc.add((Fieldable)new Field("date", "20131101", Field.Store.YES, Field.Index.NOT_ANALYZED));
/* 104 */     doc.add((Fieldable)new Field("name", "张1", Field.Store.YES, Field.Index.NOT_ANALYZED));
/* 105 */     doc.add((Fieldable)new Field("text", "爱读书", Field.Store.YES, Field.Index.ANALYZED));
/* 106 */     indexWriter.addDocument(doc);
/*     */     
/* 108 */     indexWriter.commit();
/*     */   }
/*     */   
/*     */   private static void createIndex2() throws CorruptIndexException, IOException {
/* 112 */     IndexWriter indexWriter = LuceneTool.getIndexWriter();
/*     */     
/* 114 */     Document doc = new Document();
/* 115 */     doc.add((Fieldable)(new NumericField("date", Field.Store.YES, true)).setIntValue(20150101));
/* 116 */     doc.add((Fieldable)new Field("name", "张1", Field.Store.YES, Field.Index.NOT_ANALYZED));
/* 117 */     doc.add((Fieldable)new Field("text", "爱读书", Field.Store.YES, Field.Index.ANALYZED));
/* 118 */     indexWriter.addDocument(doc);
/*     */     
/* 120 */     doc = new Document();
/* 121 */     doc.add((Fieldable)(new NumericField("date", Field.Store.YES, true)).setIntValue(20150426));
/* 122 */     doc.add((Fieldable)new Field("name", "张2", Field.Store.YES, Field.Index.NOT_ANALYZED));
/* 123 */     doc.add((Fieldable)new Field("text", "爱运动", Field.Store.YES, Field.Index.ANALYZED));
/* 124 */     indexWriter.addDocument(doc);
/*     */ 
/*     */     
/* 127 */     doc = new Document();
/* 128 */     doc.add((Fieldable)(new NumericField("date", Field.Store.YES, true)).setIntValue(20150609));
/* 129 */     doc.add((Fieldable)new Field("name", "张3", Field.Store.YES, Field.Index.NOT_ANALYZED));
/* 130 */     doc.add((Fieldable)new Field("text", "爱玩", Field.Store.YES, Field.Index.ANALYZED));
/* 131 */     indexWriter.addDocument(doc);
/*     */     
/* 133 */     doc = new Document();
/* 134 */     doc.add((Fieldable)(new NumericField("date", Field.Store.YES, true)).setIntValue(20151211));
/* 135 */     doc.add((Fieldable)new Field("name", "张5", Field.Store.YES, Field.Index.NOT_ANALYZED));
/* 136 */     doc.add((Fieldable)new Field("text", "爱唱歌", Field.Store.YES, Field.Index.ANALYZED));
/* 137 */     indexWriter.addDocument(doc);
/*     */     
/* 139 */     doc = new Document();
/* 140 */     doc.add((Fieldable)(new NumericField("date", Field.Store.YES, true)).setIntValue(20120101));
/* 141 */     doc.add((Fieldable)new Field("name", "张6", Field.Store.YES, Field.Index.NOT_ANALYZED));
/* 142 */     doc.add((Fieldable)new Field("text", "爱读书6", Field.Store.YES, Field.Index.ANALYZED));
/* 143 */     indexWriter.addDocument(doc);
/*     */     
/* 145 */     indexWriter.commit();
/*     */   }
/*     */ }


/* Location:              D:\library\tomcat\webapps\ROOT\WEB-INF\classes\!\com\xhgk\test\Demo1.class
 * Java compiler version: 5 (49.0)
 * JD-Core Version:       1.1.3
 */